/**
 * @Author: zhangweinan
 * @Date: 2022-12-11 17:23:37
 * @LastEditors: zhangweinan
 * @LastEditTime: 2022-12-12 01:33:36
 * @Description: file content
 * @FilePath: \front-end-of-task-center\src\utils\downloadFile
 */
import { getAccessToken, getTenantId } from '@/utils/auth'
export default function downloadFile(url, fileName) {
  // const self = this
  const x = new XMLHttpRequest()
  x.open('GET', url, true)
  x.responseType = 'blob'
  x.setRequestHeader('Authorization', 'Bearer ' + getAccessToken())
  x.setRequestHeader('tenant-id', getTenantId())
  x.onload = () => {
    // self.exportLoading = false;
    const url = window.URL.createObjectURL(x.response)
    const a = document.createElement('a')
    a.href = url
    a.download = fileName
    a.click()
  }
  x.send()
}
